<?php
//
$mutitle = '投票结果';
$fcfg = devTopic::cfg2arr($cvote);
$stitle = $fcfg[$this->view];
//$dno = req('dno');
//
$db = db();
$whrs = "did='$this->key' AND part='$this->view'";
$tbfull = $db->table('topic_items',2); 
$row = $db->query("SELECT SUM(vote) as `sum`, MAX(vote) as `max` FROM $tbfull WHERE $whrs");
$sum = empty($row[0]['sum']) ? 0 : $row[0]['sum'];
$max = empty($row[0]['max']) ? 0 : $row[0]['max'];
$lists = $db->table('topic_items')->where($whrs)->order('vote DESC,top,did')->select();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
{php}
$this->pmeta();
eimp('initJs','jquery;bootstrap;comm;vote');
eimp('initCss','bootstrap,stpub;comm;topic');
{/php}
</head>

<body>

{inc:"topic/_index/_head"}

<div class="topic-header">
    <h1 class="topic-title">{title($title,96,$this->vars)}</h1>
    <p class="topic-post-meta">
        `{=$stitle}`投票结果
    </p>
</div>

<div class="row">
    <div class="col-sm-9">
        <table class="table table-bordered vote-order">
            <tr class="head">
                <th>ID</th>
                <th width="50%">投票项</th>
                <th nowrap>票数</th>
                <th nowrap class="hidden-xs">比例</th>
            </tr>
            <?php 
            foreach($lists as $ti=>$tv){ $mpic=comStore::revSaveDir($tv['mpic']); 
            $rate = $sum ? round($tv['vote']/$sum*100,2) : 0;
            $ratp = $max ? round($tv['vote']/$max*100,2) : 0;
            $bg = ($ti % 2) ? 'EEE' : 'FFF';
            ?>
            <tr style="background:#{=$bg}">
                <td>
                    {=$tv['dno']}
                </td>
                <td nowrap>
                    <div class="vote-img">
                        <img src="{=$mpic}">
                    </div>
                    <span id="dno_{=$tv['dno']}">{=$tv['title']}</span>
                    <p class="vote-bar" style="width:{=$ratp}%;"></p>
                </td>
                <td>
                    {=$tv['vote']}
                    <p class="visible-xs-block">{=$rate}%</p>
                </td>
                <td class="hidden-xs">{=$rate}%</td>
            </tr>
            <?php } $ti++; $bg = ($ti % 2) ? 'EEE' : 'FFF'; ?>
            <tr class="foot" style="background:#{=$bg}">
                <th>-</th>
                <th nowrap>总票数</th>
                <th>{=$sum}</th>
                <th class="hidden-xs">100%</th>
            </tr>
        </table>
    </div><!-- /.blog-main -->
    <div class="col-sm-3 topic-sidebar hidden-xs">
        {inc:"topic/_index/_side1"}
        {inc:"topic/_index/_side2"}
    </div>
</div><!-- /.row -->

{inc:"topic/_index/_foot"}
<script>voteImg(); voteItem();</script>

</body>
</html>
